//
//  SEHomeKindView.m
//  kuaiyi
//
//  Created by Alphts on 16/7/5.
//  Copyright © 2016年 Alphts. All rights reserved.
//
//本View用于九宫格View的设置
#import "SEHomeKindView.h"

@interface SEHomeKindView ()

@property (nonatomic, weak) UIButton *button;

@property (nonatomic, weak) UILabel *lb_title;

@end

@implementation SEHomeKindView


- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
        [self setupContraint];
    }
    return self;
}

#pragma mark - 创建控件
- (void)setupUI{
    
    self.backgroundColor = [UIColor whiteColor];
    
    //创建button
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button = button;
    
    //添加点击事件
    [button addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:button];
    
    //创建label
    UILabel *lb_title = [[UILabel alloc] init];
    self.lb_title = lb_title;
    [self addSubview:lb_title];
    
}

#pragma mark - 设置约束
- (void)setupContraint{
    [self.lb_title makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self);
        make.bottom.equalTo(self.bottom).offset(-10);
        make.height.equalTo(21);
    }];
    
    [self.button makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self);
        make.centerY.equalTo(self).offset(-10);
        make.height.equalTo(self.mas_width).multipliedBy(0.55);
        make.width.equalTo(self.button.mas_height);
    }];
}

#pragma mark - 重写set方法 给数据赋值
- (void)setTitle:(NSString *)title{
    _title = title;
    self.lb_title.text = title;
}

- (void)setImgName:(NSString *)imgName{
    _imgName = imgName;
    [self.button setBackgroundImage:[UIImage imageNamed:imgName] forState:UIControlStateNormal];
  
    [self.button sizeToFit];
}

- (void)setIndex:(NSInteger)index{
    
    _index = index;
    self.button.tag = index;
}


//点击按钮  block传递信息
- (void)didClickButton:(UIButton *)sender{
    
    if (self.kindViewBlock) {
        self.kindViewBlock(sender.tag);
    }
    
}


@end
